<?php

namespace app\admin\model\finance\extract;

use think\Model;

class Task extends Model
{
    // 表名
    protected $name = 'finance_extract_task';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'type_text',

    ];
    public function getTypeList()
    {
        return ['1' => __('Type 1'),'2' =>__('Type 2')];
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }  
   
    public function week()
    {
        return $this->belongsTo('Week', 'extract_week', 'id', [], 'LEFT')->setEagerlyType(0);
    }  
    public function taskotreach()
    {
        return $this->belongsTo('taskOut', 'id', 'task_id', [], 'LEFT')->setEagerlyType(0);
    } 
    public function taskbook()
    {
        return $this->belongsTo('app\admin\model\integral\TaskBook', 'id', 'task_id', [], 'LEFT')->setEagerlyType(0);
    }
     public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'userid', 'userid', [], 'LEFT')->setEagerlyType(0);
    }
}
